/**
 * Created by easy on 15/5/12.
 */

$(document).ready(function(){
});
(function(){
    basic.deviceReady = function(){
        if(mc.device == iOS) {
            $("#clearCache").show();
        }
        mc.showContent();
        if(!vars.userInfo){
            mc.getUserInfo(function (data) {
                vars.userInfo = JSON.parse(data);
                $("#username").text(vars.userInfo.username);
                mc.getAppMode(function (data) {
                    //alert(JSON.stringify(data))
                    if(data.data == "true" || data == "ON"){
                        $('.switch-WiFi').attr("checked", "true");
                    }
                    var disturbance = document.querySelector('.switch-disturbance');
                    var switchery = new Switchery(disturbance, { color: '#52D569'});
                    var WiFi = document.querySelector('.switch-WiFi');
                    var switchery = new Switchery(WiFi, { color: '#52D569'});
                });
            });
        }
        var appMode = document.querySelector('.switch-WiFi');
        appMode.addEventListener('change', function() {
            //mc.notification("请稍候...", "Normal");
            mc.setAppMode(appMode.checked, function () {
                if(!appMode.checked) {
                    mc.uploadAllAjaxTask(function () {
                        //mc.notification("", "Close");
                    });
                } else {
                    //mc.notification("", "Close");
                }
            });
        });
        mc.saveDataToLocalStorage("dynamicItem", 1, function () {

        }, "app");
    };
    basic.viewDidAppearCallback = function(){

    };

    util.clearCache = function () {
        mc.confirm("清除缓存", function () {
            mc.clearCache();
        }, "是否确定删除缓存");
    }

})();